package com.xyht.medicine_management_system.modules.consumptionPoint.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.annotation.RequestPass;
import com.xyht.medicine_management_system.common.commonReturn.CommonResult;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.consumptionPoint.entity.req.MmsConsumptionPointShopReq;
import com.xyht.medicine_management_system.modules.consumptionPoint.entity.req.SubmitOrderByPointReq;
import com.xyht.medicine_management_system.modules.consumptionPoint.service.MmsConsumptionPointShopService;
import com.xyht.medicine_management_system.modules.order.entity.req.SubmitOrderReq;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * <p>
 * 积分商城表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-07
 */
@RestController
@SecretBody
@RequestMapping("/pointShop")
public class MmsConsumptionPointShopController {
    @Resource
    private MmsConsumptionPointShopService mmsConsumptionPointShopService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("添加积分商城商品")
    @PostMapping("/add")
    public ResponseResult addConsumptionPointShop(@RequestBody MmsConsumptionPointShopReq pointShopReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsConsumptionPointShopService.addConsumptionPointShop(pointShopReq, userId);
    }

    @ApiModelProperty("删除积分商城商品")
    @PostMapping("/del")
    public ResponseResult delConsumptionPointShop(@RequestParam("pointShopId") String[] pointShopId) {
        mmsConsumptionPointShopService.removeByIds(Arrays.asList(pointShopId));
        return CommonResult.success();
    }

    @ApiModelProperty("修改积分商城商品")
    @PostMapping("/update")
    public ResponseResult updateConsumptionPointShop(@RequestBody MmsConsumptionPointShopReq pointShopReq) {
        return mmsConsumptionPointShopService.updateConsumptionPointShop(pointShopReq);
    }

    @ApiModelProperty("积分商城商品列表")
    @RequestPass
    @GetMapping("/list")
    public ResponseResult listConsumptionPointShop(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "status", required = false) Integer status,
                                                   @RequestParam(value = "searchStr", required = false) String searchStr) {
        return mmsConsumptionPointShopService.listConsumptionPointShop(pageNum, pageSize, status, searchStr);
    }

    @ApiModelProperty("积分商城商品详情")
    @RequestPass
    @GetMapping("/detail")
    public ResponseResult pointShopDetail(@RequestParam("pointShopId") String pointShopId) {
        return mmsConsumptionPointShopService.pointShopDetail(pointShopId);
    }

    @ApiOperation("提交订单(使用积分)")
    @PostMapping("/submit")
    public ResponseResult submitOrderByPoint(@RequestBody SubmitOrderByPointReq orderReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsConsumptionPointShopService.submitOrderByPoint(orderReq, userId);
    }
}

